package org.test.future;

/**
 * 服务器端
 * @author wb-chenkang
 *
 */
public class HostServer {

	public Data request(final int count, final char c) {
		System.out.println("    request(" + count + ", " + c + ") BEGIN");

		// (1) 建立FutureData的实体
		final FutureData future = new FutureData();

		// (2) 为了建立RealData的实体，启动新的线程
		new Thread() {
			public void run() {
				RealData realdata = new RealData();
				realdata.addObserver(future);// 设置观察者，以便当RealData把数据准备完毕后，通过该回调口子，通知FutureData表示数据已经贮备好了
				realdata.createRealData2(count, c);
			}
		}.start();

		System.out.println("    request(" + count + ", " + c + ") END");
		// (3) 取回FutureData实体，作为传回值
		return future;
	}
}
